//
//  SerialNumberWinCon.m
//  Investigation Catalyst
//
//  Created by Tobias Haughton on Thu Feb 19 2004.
//  Copyright (c) 2004 Starline Software Ltd. All rights reserved.
//

#import "SSSerialNumberPanelController.h"
#import "SSCatalystAppController.h"

@implementation SSSerialNumberPanelController

- (id)init {
   self = [super initWithWindowNibName:@"SerialNumberPanel"];
   if (self) {
      [self setWindowFrameAutosaveName:@"SerialNumberPanel"];
   }
   return self;
}


- (IBAction)enterSerialNumber:(id)sender
{
   if([(SSCatalystAppController *)[NSApp delegate] isValidSerialNumber:[serialNumberField stringValue]]) {
      //add number to defaults
      [[NSUserDefaults standardUserDefaults] setObject:[serialNumberField stringValue] forKey:SSCatalystSerialNumberKey];

      if(![(SSCatalystAppController *)[NSApp delegate] isSerialNumberActivated:[serialNumberField stringValue]]) {
         //not activated
         int choice = NSRunAlertPanel(NSLocalizedString(@"Alert", nil), NSLocalizedString(@"ActivateSerialNumberQuery", nil), @"Yes", @"No", nil, nil);

         if(choice == NSAlertDefaultReturn) {
            [(SSCatalystAppController *)[NSApp delegate] activate];
         }
      }
      
      [[self window] close];
   } else {
      NSRunAlertPanel(NSLocalizedString(@"Alert", nil), NSLocalizedString(@"InvalidSerialNumber", nil), @"OK", nil, nil, nil);
   }
   
   
}

@end
